package news.utils.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;
  
  
public class StringUtils extends org.apache.commons.lang.StringUtils {  
  
  
    public static String getRegexIndex(final String str, final String regex, final int index) {  
        if (isNotBlank(regex) && isNotBlank(str)) {  
            if (index >= 1) {  
                Pattern pattern = Pattern.compile(regex);  
                Matcher matcher = pattern.matcher(str);  
                while (matcher.find()) {  
                    if (matcher.groupCount() < index) {  
                        LoggerUtils.warn("Index Is OutOfBounds!");  
                    } else {  
                        return matcher.group(index);  
                    }  
                    return "";  
                }  
            } else {  
                LoggerUtils.warn("Index Is Illegal!");  
            }  
        } else {  
            LoggerUtils.warn("Str Or Regex Is Blank!");  
        }  
        return null;  
    }  
}  
